<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>传送门teleport功能</title>
    <script src="../vue.global.js"></script>
    <style>
        .area {
            position: absolute;
            left: 50%;
            top: 50%;
            transform: translate(-50%, -50%);
            width: 200px;
            height: 300px;
            background: green;
        }

        .mask {
            position: absolute;
            left: 0;
            right: 0;
            top: 0;
            bottom: 0;
            background: #000;
            opacity: 0.5;
        }

        .destination {
            position: absolute;
            top: 20px;
            left: 20px;
            width: 100px;
            height: 100px;
            background: red;
        }
    </style>
</head>
<body>
<div id="app">
    <div id="destination"></div>
</div>

<script>
    //自定义传送门 directive
    // 它允许您将组件的内容渲染到DOM中的任何位置，而不受父组件的限制。
    const app = Vue.createApp({
        data() {
            return {
                show: false
            }
        },
        methods: {
            handleClick() {
                this.show = !this.show;
            }
        },
        template: `
          <div class="area">
          <button @click="handleClick">按钮</button>
          <teleport to="body">
            <div class="mask" v-show="show"></div>
          </teleport>
          </div>
        `
    });
    const vm = app.mount("#app");
</script>
</body>
</html>